home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
Inspectors
/
YourWS_Inspector
/
Text_Console.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
1KB
|
42 lines
/*
---------Text_Console.h------------
Adds a printf method to all Text instances within an application.
Thanks to Sam Streeper for posting the original version of this stuff to
the world.
You may freely copy, distribute, and reuse the code in this example.
NeXT disclaims any warranty of any kind, expressed or implied, as to its
fitness for any particular use.
------------------------------------
*/
#import "Text_Console.h"
#import <stdarg.h>
@implementation Text(Text_Console)
#define BUFFERSIZE 512
- (int) printf:(const char *) format, ...
{
int result, length = [self textLength];
char buffer[BUFFERSIZE];
va_list ap;
va_start(ap, format);
result = vsprintf(buffer, format, ap);
va_end(ap);
// this is how one puts text into a Text object and goes to that selection.
// put the cursor in the very last location and push the buffer in
[[self setSel:length :length] replaceSel:buffer];
// scroll so that it is visible and redisplay
[[self scrollSelToVisible] display];
return result;
}
@end